package com.ctbri.manage;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Collectors;
import java.util.Collections;
import java.util.Comparator;

import com.ctbri.manage.quality.original.CheckBasic;
import lombok.Setter;
import lombok.Getter;
/**
 * Hello world!
 *
 */
public class App {
    public static void main( String[] args ) throws FileNotFoundException,
            UnsupportedEncodingException,
            ClassNotFoundException,
            InstantiationException,
            IllegalAccessException,
            NoSuchFieldException,
            NoSuchMethodException,
            InvocationTargetException {
        A aa = new A();
        System.out.println(aa.getAtt1());
        System.out.println(aa.add("abing and "));
        Class<?> c = Class.forName("com.ctbri.manage.A");
        System.out.println(c);
        Method[] methods = c.getDeclaredMethods();
//        for (Method m: methods) System.out.println(m.getName());
        Field f1 = c.getDeclaredField("att1");
        //f1.setAccessible(true);
        f1.set(aa, 10);
        Field f2 = c.getDeclaredField("att2");
       // f2.setAccessible(true);
        f2.set(aa, new String[]{"xing", "bing", "qian"});
        System.out.println(aa.getAtt1());
        System.out.println(aa.add("abing and "));
        Method m2 = c.getDeclaredMethod("add", int.class);
        int result = (int) m2.invoke(aa, 100);
        System.out.println(result);
        System.out.println();
        Constructor<?> con = c.getDeclaredConstructor(new Class[]{int.class, String[].class});
        Object obj = con.newInstance(1, new String[]{"a", "b", "c"});
        System.out.println(((A)obj).getAtt1() + " " + ((A)obj).add(""));
        System.out.println(c.getPackage());
        System.out.println();
        int[] intArray = (int[]) Array.newInstance(int.class, 3);
        Array.set(intArray, 0, 123);
        Array.set(intArray, 1, 456);
        Array.set(intArray, 2, 789);
        for (int i=0; i<intArray.length; ++i) System.out.println(Array.get(intArray, i));
    }
}

class A{
    @Setter @Getter protected int att1;
    @Setter @Getter protected String[] att2;
    A(final int att1, final String[] att2){
        this.att1 = att1;
        this.att2 = att2;
    }
    A(){
        this.att1 = 3;
        this.att2 = new String[]{"song", "yun", "long"};
    }
    public int add(final int a){
        return this.att1 + a;
    }
    public String add(final String b){
        return b + String.join("", this.att2);
    }
}
class B extends A{
    public String att3;
    B(final int att1, final String[] att2, final String att3){
        super(att1, att2);
        this.att3 = att3;
    }
}